package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameInfoTimeLimit extends JFrame
	{
		//members define
		private var paneIcon:JPanel;
		private var panelInfo:JPanel;
		private var txtInfo:JTextField;
		private var labelClose:JLabel;
		public function FrameInfoTimeLimit()
		{
			super();
			setDragable(false);
			setClosable(false);
			setResizable(false);
			setTitleBar(null);
			setBorder(new EmptyBorder());
			setBackgroundDecorator(new SolidBackground(new ASColor(0,0)));
			
			//component creation
			setSize(new IntDimension(400, 400));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			paneIcon = new JPanel();
			paneIcon.setLocation(new IntPoint(5, 5));
			paneIcon.setSize(new IntDimension(45, 45));
			paneIcon.setPreferredSize(new IntDimension(45, 45));
			
			panelInfo = new JPanel();
			panelInfo.setLocation(new IntPoint(55, 5));
			panelInfo.setSize(new IntDimension(200, 45));
			//panelInfo.setPreferredSize(new IntDimension(200, 45));
			var layout1:BoxLayout = new BoxLayout();
			layout1.setAxis(AsWingConstants.VERTICAL);
			layout1.setGap(0);
			panelInfo.setLayout(layout1);
			
			txtInfo = new JTextField();
			txtInfo.setLocation(new IntPoint(55, 5));
			txtInfo.setSize(new IntDimension(100, 25));
			//txtInfo.setPreferredSize(new IntDimension(100, 25));
			
			labelClose = new JLabel();
			labelClose.setLocation(new IntPoint(55, 35));
			labelClose.setSize(new IntDimension(100, 15));
			//labelClose.setPreferredSize(new IntDimension(100, 15));
			labelClose.setText("3秒后自动关闭");
			
			//component layoution
			getContentPane().append(paneIcon);
			getContentPane().append(panelInfo);
			
			panelInfo.append(txtInfo);
			panelInfo.append(labelClose);
			
			img_info_motion_failed = new AssetBackground(Client.getUIElement("img_info_motion_failed") as DisplayObject);
			img_info_motion_success = new AssetBackground(Client.getUIElement("img_info_motion_success") as DisplayObject);
			paneIcon.setBackgroundDecorator(img_info_motion_failed);
			txtInfo.setBackgroundDecorator(null);
			txtInfo.setEditable(false);
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 14, true, false, false, false);
			filter = new GlowFilter(ASColor.BLACK.getRGB(), 1, 2, 2, 2);
			txtInfo.setFont(font);
			txtInfo.setForeground(ASColor.ORANGE);
			txtInfo.filters = new Array(filter);
			
			font = new ASFont("宋体", 12, false, false, false, false);
			labelClose.setForeground(ASColor.GREEN);
			labelClose.setFont(font);
			labelClose.setTextFilters(new Array(filter));
			
		}
		private var img_info_motion_failed:AssetBackground = null;
		private var img_info_motion_success:AssetBackground = null;
		public function setData(message:String,type:int):void
		{
			txtInfo.setHtmlText(message);
			//var dim:IntDimension  = AsWingUtils.computeStringSizeWithFont(txtInfo.getFont(),txtInfo.getHtmlText());
			//txtInfo.setPreferredSize(dim);
			paneIcon.setBackgroundDecorator(type == Const.INFO_TYPE_FAILED?img_info_motion_failed:img_info_motion_success);
			panelInfo.pack();
			panelInfo.paintImmediately();
			pack();
			paintImmediately();
			if(_timerClose == null)
			{
				_timerClose = new Timer(3000);
				_timerClose.addEventListener(TimerEvent.TIMER,onTimerClose);
			}
			if(_timerClose.running)
			{
				_timerClose.stop();
				_timerClose.reset();
			}
			_timerClose.start();
			
			if(_tween != null)
			{
				_tween.clear();
				_tween = null;
			}
			var width:int = 10 + paneIcon.width + panelInfo.width;
			var height:int = 55;
			setSize(new IntDimension(width, height));
			

			var square:Sprite = new Sprite();

			square.graphics.beginFill(0x033332, 0.8);
			square.graphics.drawRoundRectComplex(0,0,width,height,5,5,5,5);
			square.graphics.endFill();
			setBackgroundDecorator(new AssetBackground(square as DisplayObject));
		}
		
		private var _tween:TweenLite = null;
		private function onTimerClose(e:TimerEvent):void
		{
			_timerClose.stop();
			//FrameInfoTimeLimit.hide();
			
			_tween = TweenLite.to(this, 0.5, {x:this.x, y:-this.height,onComplete:function():void
			{
				FrameInfoTimeLimit.hide();
				_frame.txtInfo.setHtmlText("");
				_frame.txtInfo.setText("");
				_tween = null;
			}});
			
		}
		
		public static var _timerClose:Timer = null;
		private static var _frame:FrameInfoTimeLimit = null;
		public static function show(message:String,type:int):void
		{
			if(_frame == null)
			{
				_frame = new FrameInfoTimeLimit;
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			_frame.setData(message,type);
			PanelMainHelp.getInstance().bringToTop(_frame);
			//if(_frame.txtInfo.getText() == message)
			//{
			//	_frame.x = (Engine.W - _frame.width)/2;
			//	_frame.y = 100;
			//}
			//else
			//{
				_frame.x = (Engine.W - _frame.width)/2;
				_frame.y = -_frame.height;//(Engine.H - _frame.height - 27);
				if(_frame._tween != null)
				{
					_frame._tween.clear();
					_frame._tween = null;
				}
				_frame._tween = TweenLite.to(_frame, 0.5, {x:_frame.x, y:100,onComplete:function():void
				{
					//FrameInfoTimeLimit.hide();
					_frame._tween = null;
				}});
			//}
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}